package mypazar.denemecartago;

import cartago.ArtifactId;
import cartago.CartagoException;
import cartago.Op;
import cartago.util.agent.CartagoBasicContext;

public class DenemeCartagoCtx2 extends Thread {

	private static final String PAZAR_ENV_NAME = "pazar";
	public static final String AGENT_NAME_SMAN2 = "salesman2";
	private static final String BUYING_PRODUCT_NAME = "apple";
	private static int BUYING_QUANTITY = 5;

	ArtifactId artifactId;

	public DenemeCartagoCtx2(ArtifactId artifactId) {
		this.artifactId = artifactId;
	}

	public void run() {

		try {
			doOperations(artifactId);
		} catch (ActionFailedException e) {
			e.printStackTrace();
		} catch (CartagoException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	/**
	 * @param artifactId
	 * @throws CartagoException
	 * @throws ActionFailedException
	 * @throws InterruptedException
	 */
	private void doOperations(ArtifactId artifactId) throws CartagoException,
			ActionFailedException, InterruptedException {
		CartagoBasicContext ctX2 = new CartagoBasicContext(AGENT_NAME_SMAN2,
				PAZAR_ENV_NAME);

		ctX2.doAction(artifactId, new Op("sayHello"));

		ctX2.doAction(artifactId, new Op("sell", BUYING_PRODUCT_NAME,
				BUYING_QUANTITY));

		ctX2.doAction(artifactId, new Op("sell", BUYING_PRODUCT_NAME, 6));

		ctX2.doAction(artifactId, new Op("askPrice", BUYING_PRODUCT_NAME));

		// AgentId agentID = new AgentId(AGENT_NAME_SMAN2, "40", 10, "Salesman",
		// workspace.getId());
		//
		// AgentIdCredential agentIdCredential = new AgentIdCredential(
		// AGENT_NAME_SMAN2);
		//
		// WorkspaceKernel kernel = workspace.getKernel();
		//
		// ArtifactId stallArtifactId = kernel.makeArtifact(agentID, "Stall",
		// "mypazar.cartago.Stall",
		// new ArtifactConfig(STALL1_PRODUCT_NAME));
		//
		// ICartagoSession session = CartagoService.startSession(PAZAR_ENV_NAME,
		// agentIdCredential, null);
	}
}
